package com.hs.srm.task;

import com.hs.srm.admin.modules.harmfulsubstance.service.DeclarationFormHeadService;
import com.hs.srm.admin.modules.harmfulsubstance.service.ReportRepositoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @Description 有害物质定时任务
 * @Author ych
 * @Date 2020-03-18
 */
@Component("harmfulSubstanceTask")
public class HarmfulSubstanceTask {

    Logger logger = LoggerFactory.getLogger(HarmfulSubstanceTask.class);

    @Autowired
    private ReportRepositoryService reportService;

    @Autowired
    private DeclarationFormHeadService declarationFormHeadService;

    /**
     * 报告库有效性验证
     */
    public void reportValidCheck() {

        //过期报告设置
        String now = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDate.now());
        reportService.setExpiredValid(now);

        //过期前两周预警
        String after = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDate.now().plusWeeks(2));
        reportService.setWarningValid(after);
    }


    /**
     * 宣告表预警状态、生效状态
     */
    public void declarationValidCheck() {

        //预警超期，无效
        String now = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDate.now());
        declarationFormHeadService.setExpiredStatus(now);

        //过期前两周预警
        String after = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(LocalDate.now().plusWeeks(2));
        declarationFormHeadService.setWarningStatus(after);
    }


}
